using System;
using System.Text;
using System.Xml;
using System.IO;
using System.Xml.Serialization;
using System.Collections;

namespace ELS.Configuration
{
	#region ViewRegistryData
	/// <summary>
	/// Class to access data for views.
	/// </summary>
	public class ViewRegistryData
	{
		private ArrayList _views = new ArrayList();

		#region constructors
		/// <summary>
		/// Creates a new instance of ViewRegistryData..
		/// </summary>
		public ViewRegistryData()
		{
		}

		/// <summary>
		/// Creates a new instance of ViewRegistryData.
		/// </summary>
		/// <param name="viewName">name of the view.</param>
		/// <param name="typeName">name of the type.</param>
		/// <param name="assemblyName">name of the assembly.</param>
		#endregion constructors
		
		public ViewData[] Views
		{
			get 
			{
				ViewData[] items = new ViewData[ _views.Count ];
				_views.CopyTo( items );
				return items;
			}
			set 
			{
				if( value == null ) return;
				ViewData[] items = (ViewData[])value;
				_views.Clear();
				foreach( ViewData item in items )
					_views.Add( item );
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="view"></param>
		public void Add ( ViewData view )
		{
			_views.Add( view );
		}
	}
	#endregion ViewRegistryData


	public class ViewData
	{
		#region class variables
		private string _viewName		= null;
		private string _typeName		= null;
		private string _assemblyName	= null;
		private ViewType _viewType		= ViewType.Primary;
		private bool _multiple			= false;
		private bool _showOnLoad		= false;
		private bool _availableOnToolBar= false;
		#endregion class variables

		#region constructors
		/// <summary>
		/// Creates a new instance of ViewData..
		/// </summary>
		public ViewData()
		{
		}

		/// <summary>
		/// Creates a new instance of ViewData.
		/// </summary>
		/// <param name="viewName">name of the view.</param>
		/// <param name="typeName">name of the type.</param>
		/// <param name="assemblyName">name of the assembly.</param>
		public ViewData(string viewName, string typeName, string assemblyName )
		{
			_viewName		= viewName;
			_typeName		= typeName;
			_assemblyName	= assemblyName;
		}

		#endregion constructors

		#region public properties
		/// <summary>
		/// Gets or sets the view name.
		/// </summary>
		public string ViewName
		{
			get { return _viewName;  }
			set { _viewName = value; }
		}

		/// <summary>
		///  Gets or sets the type name.
		/// </summary>
		public string TypeName
		{
			get { return _typeName;  }
			set { _typeName = value; }
		}


		/// <summary>
		/// Gets or sets the assembly name.
		/// </summary>
		public string AssemblyName
		{
			get { return _assemblyName;  }
			set { _assemblyName = value; }
		}

		/// <summary>
		/// Gets or sets the view type.
		/// </summary>
		public ViewType ViewType
		{
			get { return _viewType;  }
			set { _viewType = value; }
		}


		/// <summary>
		/// Gets or sets if multiple instances of the view can be instantiated.
		/// </summary>
		public bool Multiple
		{
			get { return _multiple;  }
			set { _multiple = value; }
		}

		/// <summary>
		/// Gets or sets if the view is shown on load of the application. 
		/// </summary>
		public bool ShowOnLoad
		{
			get { return _showOnLoad;  }
			set { _showOnLoad = value; }
		}

		/// <summary>
		/// Gets or sets if the view is available on the search toolbar.
		/// </summary>
		public bool AvailableOnToolBar
		{
			get { return _availableOnToolBar;  }
			set { _availableOnToolBar = value; }
		}
		#endregion public properties

		#region overrides
		public override string ToString()
		{
			StringBuilder sb = new StringBuilder();
			StringWriter writer = new StringWriter(sb);
			XmlSerializer serializer = new XmlSerializer( this.GetType());
			serializer.Serialize(writer,this);
			return sb.ToString();
		}

		#endregion overrides

	}


	#region ViewType
	public enum ViewType
	{
		Primary		= 1,
		Auxiliary	= 2
	}
	#endregion ViewType

}
